// 在src/components/ 或其他适当位置新建一个文件，如 LightSweepMaterial.js
import * as THREE from 'three';
import { TextureLoader } from 'three/src/loaders/TextureLoader';

class LightSweepMaterial extends THREE.ShaderMaterial {
	constructor() {
		super({
			transparent: true,
      depthWrite: false, // 确保透明部分不会影响深度缓冲区
      blending: THREE.NormalBlending, // 标准混合模式
			uniforms: {
				ringWidth: { value: 0.0 },
				innerRadius: { value: 0.0 },
				uTexture: { value: new TextureLoader().load('http://47.105.210.118:10005/json/texture.png') },
			},
			vertexShader: /* glsl */ `
        varying vec2 vUv;
    
        void main() {
          vUv = uv;
          gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
        }
      `,
			fragmentShader: /* glsl */ `
        varying vec2 vUv;  
        uniform float ringWidth;
        uniform float innerRadius;
        uniform sampler2D uTexture; 
    
        void main() {
          float dist = distance(vUv - 0.5, vec2(0.0));
          float patternInner = step(innerRadius, dist*2.0);
          float patternOuter = step(1.0 - (innerRadius + ringWidth), 1.0 - dist*2.0);
          float pattern = patternInner * patternOuter;

          vec4 texture = texture2D(uTexture, vUv);
          gl_FragColor = vec4(pattern*texture.r*1.0, pattern*texture.g*1.0, pattern*texture.b*1.4, texture.a*pattern);
        }
      `,
		});
	}
}

export default LightSweepMaterial;